/*
package com.yc.meeting_attendance;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.hardware.Camera;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.IdRes;
import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.google.gson.reflect.TypeToken;
import com.hwangjr.rxbus.RxBus;
import com.hwangjr.rxbus.annotation.Subscribe;
import com.hwangjr.rxbus.annotation.Tag;
import com.yc.meeting_attendance.adapter.AttendanceAdapter;
import com.yc.meeting_attendance.adapter.Gallery_adapter;
import com.yc.meeting_attendance.entity.Attachment;
import com.yc.meeting_attendance.entity.AttendanceResutl;
import com.yc.meeting_attendance.entity.ImageResutl;
import com.yc.meeting_attendance.entity.MeetingCheck;
import com.yc.meeting_attendance.entity.MeetingResutl;
import com.yc.meeting_attendance.entity.PersonnelResutl;
import com.yc.meeting_attendance.entity.Resutl;
import com.yc.meeting_attendance.fragment.SetDiagFragment;
import com.yc.meeting_attendance.net.AbsAPICallback;
import com.yc.meeting_attendance.net.Api;
import com.yc.meeting_attendance.service.CheckCardExistService;
import com.yc.meeting_attendance.utils.AutoText;
import com.yc.meeting_attendance.utils.DatetimeUtil;
import com.yc.meeting_attendance.utils.DisplayUtil;
import com.yc.meeting_attendance.utils.MyFileUtils;
import com.yc.meeting_attendance.utils.MyFunc;
import com.yc.meeting_attendance.utils.RealmHelper;
import com.yc.meeting_attendance.utils.SerialHelper;
import com.yc.meeting_attendance.utils.SharePreferenceUtil;
import com.yc.meeting_attendance.utils.ThreadUtil;
import com.yc.meeting_attendance.utils.sortClass;
import com.yc.nfc.CardInfo;
import com.yc.nfc.ComBean;

import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Timer;
import java.util.TimerTask;

import io.realm.RealmResults;
import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;
import rx.Subscriber;

import static com.yc.meeting_attendance.utils.DatetimeUtil.getSysDate;

public class MeMainActivity extends Activity implements View.OnClickListener {
    private static final String TAG = MeMainActivity.class.getSimpleName();
    private TextView tiem;
    private TextView week;
    private TextView date;
    private ImageView set;
    private TextView place;
    Intent intent1;
    SurfaceView preview;
    private Camera mCamera;
    SurfaceHolder mSurfaceHolder;
    private ViewGroup mMoreLayout, mMoreLayouts, mMoreLayoutss;
    LinearLayout linearLayout;
    ViewGroup.LayoutParams layoutParams;
    GridView listView;
    RealmHelper realmHelper = new RealmHelper(this);
    List<MeetingCheck> list1 = new ArrayList<>();
    List<String> MeetingId = new ArrayList<>();
    List<String> BigenCard = new ArrayList<>();
    List<String> EndCard = new ArrayList<>();
    List<String> ImgaViewIndex = new ArrayList<>();
    List<List<String>> ImgaView = new ArrayList<>();
    TextView practical;
    int indexBigen;
    int indexEnd;
    int realized = 0;
    SoundPool soundPool = null;
    SoundPool soundPool1 = null;
    SoundPool soundPool2 = null;
    int sourceid = 0;
    int failure = 0;
    int credit = 0;
    boolean isSoundReady;
    boolean subscript;
    List<PersonnelResutl> list = new ArrayList<>();
    AttendanceAdapter attendanceAdapter;
    Gallery main_gallery;
    LinearLayout main_lin;
    Gallery_adapter gallery_adapter;
    int current_circle = 0;
    Runnable timeadv;
    int count;
    GifImageView imgview;
    List<String> li = new ArrayList<String>();
    private SharePreferenceUtil mSharePreferenceUtil;
    Timer timerImgView;
    TimerTask taskImgView;

    LinearLayout layout_more1;

    boolean isFirst = true;
    ProgressDialog MyDialog;
    Activity myActivity;
    private SerialHelper mCom;
    private DispQueueThread DispQueue;
    private boolean isLoading = false; //是否正在上传中

    int DST_RECT_WIDTH, DST_RECT_HEIGHT;//矩形拍照尺寸
    Point rectPictureSize = null;
    int DST_CENTER_RECT_WIDTH = 280; //单位是dip
    int DST_CENTER_RECT_HEIGHT = 280;//单位是dip

    private boolean isReStart;//是否重启

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        myActivity = this;
        // 隐藏标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 隐藏状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        RxBus.get().register(this);
//        intent1 = new Intent(this, CheckCardExistService.class);
//        startService(intent1);
        mSharePreferenceUtil = MyApp.getsInstance().sharePreferenceUtil;
        setView();
        setTiem();
        message();
        personnel();
        SetImagView();

        //定时器
        Timer timerCard = new Timer();
        TimerTask tastCard = new TimerTask() {
            @Override
            public void run() {
                if (MyApp.getsInstance().getgiDestPort() == 1) {
                    MyApp.getsInstance().setCard("1");
                }


            }
        };
        timerCard.schedule(tastCard, 1000, 1000);


        mCom = new SerialHelper() {
            @Override
            protected void onDataReceived(ComBean ComRecData) {
                // TODO Auto-generated method stub
                DispQueue.AddQueue(ComRecData);
                //Log.i(STORAGE_SERVICE, "222222222222222");
            }
        };
        try {
            mCom.open();
            mCom.doSetParam();
        } catch (InvalidParameterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        DispQueue = new DispQueueThread();
        DispQueue.start();
    }


    private void setTiem() {
        tiem = getView(R.id.tiem);
        week = getView(R.id.week);
        date = getView(R.id.date);
        SetData(tiem);
        week.setText("星期" + DatetimeUtil.getWhere());
        date.setText(getSysDate("yyyy年MM月dd日"));
        new Thread(new MyThread()).start();
    }

    private void message() {
    }

    private void personnel() {
    }

    private void SetImagView() {
        AutoText autoText = getView(R.id.autoText);
        autoText.startFor0();
        main_gallery = getView(R.id.main_gallery);
        main_lin = getView(R.id.main_lin);
        preview = getView(R.id.preview);
        mSurfaceHolder = preview.getHolder();
        mSurfaceHolder.addCallback(new SufaceListener());
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mSurfaceHolder.setFixedSize(1920, 1080); //设置分辨率 640, 480
        imgview = (GifImageView) getView(R.id.imgview);
        gallery_adapter = new Gallery_adapter(this);
        main_gallery.setAdapter(gallery_adapter);
        main_gallery.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {

                return false;
            }
        });


        //设置滚动图片的时候，对应小圆点的图片切换
        main_gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                                       int position, long id) {
                View v = main_lin.getChildAt(position);
                View cuview = main_lin.getChildAt(current_circle);

                if (v != null && cuview != null) {
                    ImageView pointView = (ImageView) v;
                    ImageView curpointView = (ImageView) cuview;
                    curpointView
                            .setBackgroundResource(R.mipmap.pink);
                    pointView
                            .setBackgroundResource(R.mipmap.red);
                    current_circle = position;
                }

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        //
        timeadv = new Runnable() {

            @Override
            public void run() {
                //获取当前的图片是哪一张图片，图片的序号，
                count = main_gallery.getSelectedItemPosition();
                //当前滚动的图片序号大于多有的图片的数量，就跳转到第一张图片，否则就跳转到下一张图片
                if (count + 1 >= li.size()) {
                    count = 0;
                } else {
                    count = count + 1;
                }
                main_gallery.setSelection(count);
                handler.postDelayed(this, 2500);

            }
        };

        //开始定时器，1000毫秒切换一次图片5
        handler.postDelayed(timeadv, 2500);

    }


    private void setView() {

        place = getView(R.id.place);
        set = getView(R.id.set);
        set.setOnClickListener(this);
        place.setText(mSharePreferenceUtil.getClassId());
        listView = getView(R.id.listview);
        practical = getView(R.id.num);
        loadMusic();
        practical.setText("0/0");
        layout_more1 = getView(R.id.layout_more1);
        setupViews(R.layout.layout_depar, R.layout.layout_department, R.id.layout_more, R.id.layout_more1, R.id.tiee, realmHelper.QueryAll());

        timer.schedule(task, 1000, 1000);

        //定时器
        Timer timerCard = new Timer();
        TimerTask tastCard = new TimerTask() {
            @Override
            public void run() {
                if (MyApp.getsInstance().getgiDestPort() == 1)
                    MyApp.getsInstance().setCard("1");

                Log.d("TAG", "card:" + MyApp.getsInstance().getCard());

            }
        };
        timerCard.schedule(tastCard, 1000, 1000);


    }


    private void GetClass(final String strFlag) {

        Api.getInstance().GetMeeting(new AbsAPICallback<AttendanceResutl>(this) {

            @Override
            public void onCompleted() {
                Log.e("TAG", "comple---");
            }

            @Override
            public void onNext(AttendanceResutl attendanceResutl) {
                Log.e("TAG", "onNext---");
                mSharePreferenceUtil.setRestartFlag("");
                mSharePreferenceUtil.setRealized(0);
                mSharePreferenceUtil.setIndexEnd(0);
                mSharePreferenceUtil.setIndexBigen(0);
                mSharePreferenceUtil.setSubscript(false);
                mSharePreferenceUtil.setFig(false);
                mSharePreferenceUtil.setDataFig(false);

                realmHelper.deleteDogAll(MeetingResutl.class);
                realmHelper.deleteDogAll(PersonnelResutl.class);
                realmHelper.deleteDogAll(MeetingCheck.class);
                Log.e("TAG", "attendanceResutl:" + attendanceResutl.getMeeting().size());
                if (attendanceResutl.isCode()) {
                    if (attendanceResutl.getMeeting() != null) {

                        mSharePreferenceUtil.setRestartFlag(strFlag);

                        mSharePreferenceUtil.setClassId(attendanceResutl.getMeeting().get(0).getRoomName());
                        for (int i = 0; i < attendanceResutl.getMeeting().size(); i++) {
                            BigenCard.add(attendanceResutl.getMeeting().get(i).getBeginTime());
                            EndCard.add(attendanceResutl.getMeeting().get(i).getEndTime());
                            MeetingId.add(attendanceResutl.getMeeting().get(i).getUuid());

                        }
                      */
/*  ThreadUtil.getInstance().submit(new Runnable() {
                            @Override
                            public void run() {
//                                MyFileUtils.deleteFile(MyFileUtils.mListBean);
//                                MyFileUtils.deleteFile(MyFileUtils.mListBean);
//                                MyFileUtils.deleteFile(MyFileUtils.mListBean);

                                boolean isSave = MyFileUtils.saveObject2File(BigenCard, MyFileUtils.mBigenCard);
                                boolean isSave = MyFileUtils.saveObject2File(BigenCard, MyFileUtils.mBigenCard);
                                boolean isSave = MyFileUtils.saveObject2File(BigenCard, MyFileUtils.mBigenCard);
                                Log.d(TAG, "默认保存 缓存数据-PersonnelResutl-" + isSave);

                                boolean isSaveUrl = MyFileUtils.saveObject2File(li, MyFileUtils.mListAttachUrl);
                                Log.d(TAG, "默认保存课程图片URL保存--" + isSaveUrl);
                            }
                        });*//*


//                        mSharePreferenceUtil.setAdvance(attendanceResutl.getCheckrule().getInBefore());
//                        mSharePreferenceUtil.setBeLatee(attendanceResutl.getCheckrule().getBeLate());
//                        mSharePreferenceUtil.setAbsenteeisn(attendanceResutl.getCheckrule().getAbsenteeism());
//                        mSharePreferenceUtil.setNeedCheckout(attendanceResutl.getCheckrule().getNeedCheckout());
//                        mSharePreferenceUtil.setoutBefore(attendanceResutl.getCheckrule().getOutBefore());
//                        mSharePreferenceUtil.setleaveEalryint(attendanceResutl.getCheckrule().getLeaveEarly());
//                        mSharePreferenceUtil.setOutLate(attendanceResutl.getCheckrule().getOutLate());


                        for (int i = 0; i < attendanceResutl.getMeeting().size(); i++) {
                            MeetingResutl meetingResutl = new MeetingResutl();
                            meetingResutl.setBegin(attendanceResutl.getMeeting().get(i).getBeginTime());
                            meetingResutl.setEnd(attendanceResutl.getMeeting().get(i).getEndTime());
                            meetingResutl.setUuid(attendanceResutl.getMeeting().get(i).getUuid());
                            meetingResutl.setMeetingName(attendanceResutl.getMeeting().get(i).getMeetingName());
                            meetingResutl.setEmcee(attendanceResutl.getMeeting().get(i).getEmcee());
                            meetingResutl.setMeetingId(attendanceResutl.getMeeting().get(i).getUuid());
                            meetingResutl.setInBefore(attendanceResutl.getMeeting().get(i).getOaMeetingcheckrule().getInBefore());
                            meetingResutl.setBeLate(attendanceResutl.getMeeting().get(i).getOaMeetingcheckrule().getBeLate());
                            meetingResutl.setNeedCheckout(attendanceResutl.getMeeting().get(i).getOaMeetingcheckrule().getNeedCheckout());
                            meetingResutl.setAbsenteeism(attendanceResutl.getMeeting().get(i).getOaMeetingcheckrule().getAbsenteeism());
                            meetingResutl.setOutBefore(attendanceResutl.getMeeting().get(i).getOaMeetingcheckrule().getOutBefore());
                            meetingResutl.setLeaveEarly(attendanceResutl.getMeeting().get(i).getOaMeetingcheckrule().getLeaveEarly());
                            meetingResutl.setOutLate(attendanceResutl.getMeeting().get(i).getOaMeetingcheckrule().getOutLate());
                            realmHelper.addDog(meetingResutl);

                            if (attendanceResutl.getMeeting().get(i).getAttachment() != null && attendanceResutl.getMeeting().get(i).getAttachment().size() != 0) {
                                for (int j = 0; j < attendanceResutl.getMeeting().get(i).getAttachment().size(); j++) {
                                    Attachment attachment = new Attachment();
                                    attachment.setMeetingId(attendanceResutl.getMeeting().get(i).getMeetingemp().get(j).getMeetingId());
                                    attachment.setAttachName(attendanceResutl.getMeeting().get(i).getAttachment().get(j).getAttachName());
                                    attachment.setAttachUrl(mSharePreferenceUtil.getServerAddress() + attendanceResutl.getMeeting().get(i).getAttachment().get(j).getAttachUrl());
                                    realmHelper.addDog(attachment);


                                }
                            }

                        }

                        for (int i = 0; i < attendanceResutl.getMeeting().size(); i++) {
                            for (int j = 0; j < attendanceResutl.getMeeting().get(i).getMeetingemp().size(); j++) {
                                PersonnelResutl personnelResutl = new PersonnelResutl();
                                personnelResutl.setUuid(attendanceResutl.getMeeting().get(i).getMeetingemp().get(j).getUuid());
                                personnelResutl.setXm(attendanceResutl.getMeeting().get(i).getMeetingemp().get(j).getXm());
                                personnelResutl.setCardNo(attendanceResutl.getMeeting().get(i).getMeetingemp().get(j).getCardNo() + "");
                                personnelResutl.setType(0);
                                personnelResutl.setTime("00:00:00");
                                personnelResutl.setInResult("4");
                                personnelResutl.setOutResult(null);
                                personnelResutl.setAttendResult("4");
                                personnelResutl.setWlkh(attendanceResutl.getMeeting().get(i).getMeetingemp().get(j).getFactoryfixId() + "");
                                personnelResutl.setMeetingId(attendanceResutl.getMeeting().get(i).getMeetingemp().get(j).getMeetingId());
                                personnelResutl.setUserId(attendanceResutl.getMeeting().get(i).getMeetingemp().get(j).getUuid());
                                personnelResutl.setLg("0");
                                realmHelper.addDog(personnelResutl);
                            }


                        }
                    }
                    indexBigen = 0;
                    indexEnd = 0;
                    mSharePreferenceUtil.setIndexBigen(0);
                    mSharePreferenceUtil.setIndexEnd(0);
                    MyApp.getsInstance().setMeetingId(MeetingId);
                    MyApp.getsInstance().setBigenCard(BigenCard);
                    MyApp.getsInstance().setEndCard(EndCard);
                    //缓存处理
                    ThreadUtil.getInstance().submit(new Runnable() {
                        @Override
                        public void run() {
                            MyFileUtils.deleteFile(MyFileUtils.MeetingId);
                            MyFileUtils.deleteFile(MyFileUtils.BigenCard);
                            MyFileUtils.deleteFile(MyFileUtils.EndCard);
                            MyFileUtils.deleteFile(MyFileUtils.mListBean);

                            MyFileUtils.saveObject2File(MeetingId, MyFileUtils.MeetingId);
                            MyFileUtils.saveObject2File(BigenCard, MyFileUtils.BigenCard);
                            MyFileUtils.saveObject2File(EndCard, MyFileUtils.EndCard);
                        }
                    });
                    //


                    place.setText(attendanceResutl.getMeeting().get(0).getRoomName());
                    setupViews(R.layout.layout_depar, R.layout.layout_department, R.id.layout_more, R.id.layout_more1, R.id.tiee, realmHelper.QueryAll());

                    li.clear();
                    for (int i = 0; i < realmHelper.QueryImag(MeetingId.get(mSharePreferenceUtil.getIndexBigen())).size(); i++) {
                        Attachment attachment = ((Attachment) realmHelper.QueryImag(MeetingId.get(mSharePreferenceUtil.getIndexBigen())).get(i));
                        li.add(attachment.getAttachUrl());
                    }
//                    Log.d("TAG","url:"+attachment.getAttachUrl());
                    Log.d("TAG", "li:" + li.size());
                    if (li.size() != 0) {
                        gallery_adapter.setList(li);
                        setCircle();
                    }

                    Log.d("TAG", "QueryAll:" + realmHelper.QueryAll().size());
                }
            }

            //
            @Override
            public void onError(Throwable e) {

                super.onError(e);
                if (e instanceof ConnectException) {
                    Toast.makeText(MeMainActivity.this, "网络异常,请检查网络", Toast.LENGTH_SHORT).show();
                }
                if(e instanceof SocketTimeoutException){
                    Toast.makeText(MeMainActivity.this, "网络异常,请检查网络 超时", Toast.LENGTH_SHORT).show();
                }
                Log.e("TAG", "e：" + e.getMessage());

            }


        }, mSharePreferenceUtil.getEquipment(), getSysDate("yyyy-MM-dd HH:mm:ss"));


        //取现在时间
    }

    //设置滚动图片的小圆点
    private void setCircle() {
        main_lin.removeAllViews();
        ImageView iv = null;
        for (int i = 0; i < li.size(); i++) {
            iv = new ImageView(MeMainActivity.this);
            //循环创建小圆点，判断第一个小圆点为白色的，其他的都是透明的
            if (i == 0) {
                iv.setBackgroundResource(R.mipmap.red);
            } else {
                iv.setBackgroundResource(R.mipmap.pink);
            }

            main_lin.addView(iv);

            //设置小圆点的margin值
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1);  // , 1�ǿ�ѡд��
            lp.setMargins(5, 10, 5, 10);
            iv.setLayoutParams(lp);

        }
    }

    private void setupViews(int layout1, int layout2, int layout3, int layout4, int layout5, List<MeetingResutl> list) {

        mMoreLayout = getView(layout3);   //找到该容器（这里的控件为LinearLayout，转换为ViewGroup是因为ViewGroup是容器的基类）
        mMoreLayouts = getView(layout4);
        mMoreLayoutss = getView(layout5);
        mMoreLayout.removeAllViews();
        mMoreLayouts.removeAllViews();
        mMoreLayoutss.removeAllViews();

        */
/**
         * 由于文字也是动态生成，这里用数组比较多余，使用android中array文件定义资源文件，并取出(便于管理，文字和代码分开，日后要修改直接找资源数组文件便可，不用找代码)
         *//*

//        final String[] categories = {""};
        final String[] categoriess = {"主题", "时间", "主持人"};


        */
/**
         * 动态添加布局方法封装
         * 参数 1.父容器    2.资源文字数组  3.从第几个开始   4.行数
         *//*

        if (list.size() != 0) {
            // fillView(mMoreLayout, list, layout2);
            //fillViews(mMoreLayout, list, layout2);
            fillView(mMoreLayout, mMoreLayouts, list, layout2);
        }
//        fillViewsOne(mMoreLayouts, categories, layout1);
        fillViewsOne(mMoreLayoutss, categoriess, layout1);

    }

    public void fillViews(ViewGroup layout, List<MeetingResutl> list, int lone) {
        String firstCategory = null;
        String secondCategory = null;
        String thirdCategory = null;
        Log.d("TAG", "size:" + list.size());
        for (int i = 0; i < 3; i++) {
            if (list.size() == 1) {
                if (i == 0) {
                    firstCategory = list.get(0).getMeetingName();
                } else if (i == 1) {
                    firstCategory = DatetimeUtil.gethour(list.get(0).getBegin()) + " - " + DatetimeUtil.gethour(list.get(0).getEnd());
                }
                if (i == 2) {
                    firstCategory = list.get(0).getEmcee();
                }

            } else if (list.size() == 2) {
                if (i == 0) {
                    firstCategory = list.get(0).getMeetingName();
                    secondCategory = list.get(0).getMeetingName();

                } else if (i == 1) {
                    firstCategory = DatetimeUtil.gethour(list.get(0).getBegin()) + " - " + DatetimeUtil.gethour(list.get(0).getEnd());
                    secondCategory = DatetimeUtil.gethour(list.get(1).getBegin()) + " - " + DatetimeUtil.gethour(list.get(1).getEnd());
                }
                if (i == 2) {
                    firstCategory = list.get(0).getEmcee();
                    secondCategory = list.get(1).getEmcee();
                }

            } else if (list.size() == 3) {
                if (i == 0) {
                    firstCategory = list.get(0).getEmcee();
                    secondCategory = list.get(1).getEmcee();
                    thirdCategory = list.get(2).getEmcee();
                } else if (i == 1) {
                    firstCategory = list.get(0).getMeetingName();
                    secondCategory = list.get(1).getMeetingName();
                    thirdCategory = list.get(2).getMeetingName();
                }
                if (i == 2) {
                    firstCategory = list.get(0).getMeetingName();
                    secondCategory = list.get(1).getMeetingName();
                    thirdCategory = list.get(2).getMeetingName();
                }


            }

            linearLayout = new LinearLayout(this);

            // 表格第一条线
            View.inflate(this, R.layout.layout_line_horizonal, layout);
            View.inflate(this, R.layout.layout_line_vertical, linearLayout);
            // 第一个子布局
            View.inflate(this, lone, linearLayout);
            View.inflate(this, R.layout.layout_line_vertical, linearLayout);
            // 第二个子布局
            View.inflate(this, lone, linearLayout);
            View.inflate(this, R.layout.layout_line_vertical, linearLayout);

            // 第三个子布局
            View.inflate(this, lone, linearLayout);
            View.inflate(this, R.layout.layout_line_vertical, linearLayout);

            layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            layout.addView(linearLayout, layoutParams);

            // 表格最后一条线
            View.inflate(this, R.layout.layout_line_horizonal, layout);

            //根据索引getChildAt到指定的位置
            final View firstView = linearLayout.getChildAt(1);
            firstView.setTag(firstCategory);        //设置tag，便于在后面判断点击的哪一个
            final TextView firstTextView = (TextView) firstView.findViewById(R.id.text_title);
            firstTextView.setText(firstCategory);   //设置文字


            final View secondView = linearLayout.getChildAt(3);
            secondView.setTag(secondCategory);
            final TextView secondTextView = (TextView) secondView.findViewById(R.id.text_title);
            secondTextView.setText(secondCategory);

            final View thirdView = linearLayout.getChildAt(5);
            thirdView.setTag(thirdCategory);
            final TextView thirdTextView = (TextView) thirdView.findViewById(R.id.text_title);
            thirdTextView.setText(thirdCategory);

        }


    }

    String firstCategory;

    public void fillView(ViewGroup layout, ViewGroup layout1, List<MeetingResutl> list, int lone) {
        if (list.size() > 0) {
            for (int i = 0; i < 3; i++) {
                //找到索引，便于根据索引添加图片文件和文字

                if (i == 0) {
                    firstCategory = list.get(0).getMeetingName();
                } else if (i == 1) {
                    firstCategory = DatetimeUtil.gethour(list.get(0).getBegin()) + " - " + DatetimeUtil.gethour(list.get(0).getEnd());
                }
                if (i == 2) {
                    firstCategory = list.get(0).getEmcee();
                }
                linearLayout = new LinearLayout(this);

                // 表格第一条线
                View.inflate(this, R.layout.layout_line_horizonal, layout);
                // 第一个子布局
                View.inflate(this, R.layout.layout_line_vertical, linearLayout);
                View.inflate(this, lone, linearLayout);
                View.inflate(this, R.layout.layout_line_vertical, linearLayout);

                layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                layout.addView(linearLayout, layoutParams);
                // 表格最后一条线
                View.inflate(this, R.layout.layout_line_horizonal, layout);

                //根据索引getChildAt到指定的位置
                final View firstView = linearLayout.getChildAt(1);
                firstView.setTag(firstCategory);        //设置tag，便于在后面判断点击的哪一个
                final TextView firstTextView = (TextView) firstView.findViewById(R.id.text_title);
                firstTextView.setText(firstCategory);   //设置文字
                layout_more1.setVisibility(View.GONE);
            }
        }
        if (list.size() == 2) {
            for (int i = 0; i < 3; i++) {
                //找到索引，便于根据索引添加图片文件和文字
                layout_more1.setVisibility(View.VISIBLE);
                if (i == 0) {
                    firstCategory = list.get(1).getMeetingName();
                } else if (i == 1) {
                    firstCategory = DatetimeUtil.gethour(list.get(1).getBegin()) + " - " + DatetimeUtil.gethour(list.get(1).getEnd());
                }
                if (i == 2) {
                    firstCategory = list.get(1).getEmcee();
                }
                linearLayout = new LinearLayout(this);

                // 表格第一条线
                View.inflate(this, R.layout.layout_line_horizonal, layout1);
                // 第一个子布局
                View.inflate(this, R.layout.layout_line_vertical, linearLayout);
                View.inflate(this, lone, linearLayout);
                View.inflate(this, R.layout.layout_line_vertical, linearLayout);

                layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                layout1.addView(linearLayout, layoutParams);
                // 表格最后一条线
                View.inflate(this, R.layout.layout_line_horizonal, layout1);

                //根据索引getChildAt到指定的位置
                final View firstView = linearLayout.getChildAt(1);
                firstView.setTag(firstCategory);        //设置tag，便于在后面判断点击的哪一个
                final TextView firstTextView = (TextView) firstView.findViewById(R.id.text_title);
                firstTextView.setText(firstCategory);   //设置文字
            }
        }
    }

    public void fillViewsOne(ViewGroup layout, String[] categories, int lone) {
        for (int i = 0; i < categories.length; i++) {
            //找到索引，便于根据索引添加图片文件和文字
            String firstCategory = categories[i];
            linearLayout = new LinearLayout(this);
            // 表格第一条线
            View.inflate(this, R.layout.layout_line_horizonal, layout);
            // 第一个子布局
            View.inflate(this, R.layout.layout_line_vertical, linearLayout);
            View.inflate(this, lone, linearLayout);
            View.inflate(this, R.layout.layout_line_vertical, linearLayout);

            layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            layout.addView(linearLayout, layoutParams);

            // 表格最后一条线
            View.inflate(this, R.layout.layout_line_horizonal, layout);

            //根                                               据索引getChildAt到指定的位置
            final View firstView = linearLayout.getChildAt(1);
            firstView.setTag(firstCategory);        //设置tag，便于在后面判断点击的哪一个
            final TextView firstTextView = (TextView) firstView.findViewById(R.id.text_title);
            firstTextView.setText(firstCategory);   //设置文字
        }
    }

*/
/*    @Subscribe(tags = @Tag("card"))
    public void onReadCard(CardInfo cardInfo) {
        //Bug
        if (MeetingId == null || MeetingId.size() <= 0) {
            Log.d("TAG", "cardInfo:MeetingId.size()=" + MeetingId.size());
            return;
        }
        //
        MeetingResutl meetingResutl = realmHelper.querMeetingResutll(MeetingId.get(indexBigen));
        Log.d("TAG", "cardInfo:" + cardInfo.getCardID());
        BigenCard = MyApp.getsInstance().getBigenCard();
        if (BigenCard.size() != 0 && indexBigen < BigenCard.size() && indexEnd < EndCard.size()) {
            String Bigen = DatetimeUtil.getDateTimeFromMillisecond(DatetimeUtil.TimeStrToSecond(BigenCard.get(indexBigen)) - 1000 * 60 * (meetingResutl.getInBefore()));
            String End = DatetimeUtil.getDateTimeFromMillisecond(
                    DatetimeUtil.TimeStrToSecond(EndCard.get(indexEnd)) + 1000 * 60 * (meetingResutl.getLeaveEarly()));
            if (realmHelper.isDogExist(cardInfo.getCardID(), MeetingId.get(indexBigen))) {
                if (DatetimeUtil.TimeCompare(getSysDate("HH:mm"), DatetimeUtil.gethour(Bigen), DatetimeUtil.gethour(End))) {

                    if (realmHelper.queryDogListMeeting(cardInfo.getCardID(), MeetingId.get(indexBigen)).size() == 1 && (meetingResutl.getNeedCheckout()) == 0) {
                        //你已签到过
                        soundPool2.play(1, 1, 1, 0, 0, 1);
                    } else {
                        if (isSoundReady) {
                            CheckCardExistService.stopAttendance();
                            Date(cardInfo.getCardID());
                            takePicture(cardInfo.getCardID());
                            soundPool.play(1, 1, 1, 0, 0, 1);
                            list = realmHelper.queryDobByAge(MeetingId.get(mSharePreferenceUtil.getIndexBigen()));
                            practical.setText(mSharePreferenceUtil.getRealized() + "/" + list.size());
                            attendanceAdapter.clear();
                            attendanceAdapter.setDate(list);
                            attendanceAdapter.notifyDataSetChanged();

                        }
                    }

                } else {
                    Toast.makeText(MeMainActivity.this, "您暂时没有需要签到的会议", Toast.LENGTH_SHORT).show();
                    soundPool1.play(1, 1, 1, 0, 0, 1);
                }
            } else {
                Log.d("TAG", "空");
                soundPool1.play(1, 1, 1, 0, 0, 1);
                Toast.makeText(MeMainActivity.this, "您不在该此会议开会", Toast.LENGTH_SHORT).show();
            }
        } else {
            soundPool1.play(1, 1, 1, 0, 0, 1);
        }

    }*//*



    private void UploadImage(String base64, String wlkh, String Userid) {

        Subscriber<ImageResutl> subscriber = new AbsAPICallback<ImageResutl>(this) {
            @Override
            public void onNext(ImageResutl imageResutl) {
                Log.d("TAG", "resutl:" + imageResutl.getMessage());
                Log.d("TAG", "isCode:" + imageResutl.isCode());

            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);

            }
        };

        Api.getInstance().UploadImageString(subscriber, "OaMeeting", base64, wlkh, Userid);
    }

    void doShowDialog() {
        MyDialog = new ProgressDialog(this, R.style.dialog);
        MyDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        MyDialog.setCanceledOnTouchOutside(false);
        MyDialog.setMessage("上传中...");
        MyDialog.setCancelable(false);
        MyDialog.show();
    }

    Date startDate = null;
    long startTime = 0;

    private void takePicture(final String whik) {
        String mUserId = "";
        MeetingCheck dog = realmHelper.queryDogById(whik);
        if (null != dog) {
            mUserId = dog.getUserId();
        }
        startDate = new Date(System.currentTimeMillis());
        startTime = startDate.getTime();
        if (mCamera != null) {

            final String finalMUserId = mUserId;
            ThreadUtil.getInstance().submit(new Runnable() {
                @Override
                public void run() {
                    mCamera.autoFocus(null);
                    mCamera.setPreviewCallback(null);
                    mCamera.takePicture(null, null, new Camera.PictureCallback() {
                        @Override
                        public void onPictureTaken(byte[] bytes, Camera camera) {
                            Date curDate = new Date(System.currentTimeMillis());
                            long time = curDate.getTime() - startTime;
                            Log.e("www1", "抓拍返回时间：" + time);
                            if (rectPictureSize == null) {
                                rectPictureSize = createCenterPictureRect(DisplayUtil.dip2px(MeMainActivity.this, DST_CENTER_RECT_WIDTH)
                                        , DisplayUtil.dip2px(MeMainActivity.this, DST_CENTER_RECT_HEIGHT));
                                DST_RECT_WIDTH = rectPictureSize.x;
                                DST_RECT_HEIGHT = rectPictureSize.y;
                            }
                            final Bitmap bitmap = BitmapFactory.decodeByteArray
                                    (bytes, 0, bytes.length);//图片
                            Matrix matrix = new Matrix();
                            matrix.setRotate(90);
                            final Bitmap Newbm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

                            int x = Newbm.getWidth() / 2 - DST_RECT_WIDTH / 2;
                            int y = Newbm.getHeight() / 2 - DST_RECT_HEIGHT / 2;
                            final Bitmap rectBitmap = Bitmap.createBitmap(Newbm, x, y, DST_RECT_HEIGHT, DST_RECT_HEIGHT);
                            final Bitmap imagBitmap = zoomImg(rectBitmap, 1080, 1000);


                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Date curDate1 = new Date(System.currentTimeMillis());
                                    long time1 = curDate1.getTime() - startTime;
                                    Log.e("www1", "抓拍返回后压缩后 时间：" + time1);
                                    Log.e("www1", "图片显示时间：" + 400);
//                                    doShowDialog();
                                    imgview.setImageBitmap(imagBitmap);
                                    imgview.setVisibility(View.VISIBLE);
                                    timerImgView = new Timer();
                                    taskImgView = new TimerTask() {
                                        @Override
                                        public void run() {
                                            // 需要做的事:发送消息  
                                            Message message = new Message();
                                            message.what = 2;

                                            handler.sendMessage(message);
                                            //异步上传图片
                                            UploadImage(DatetimeUtil.Bitmap2StrByBase64(Newbm), whik, finalMUserId);

                                            //清除bitmap
                                            if (null != Newbm && !Newbm.isRecycled()) {
                                                Newbm.recycle();
                                            }
                                            if (null != rectBitmap && !rectBitmap.isRecycled()) {
                                                rectBitmap.recycle();
                                            }
                                            if (null != bitmap && !bitmap.isRecycled()) {
                                                bitmap.recycle();
                                            }

                                        }
                                    };
                                    timerImgView.schedule(taskImgView, 800);// 1s后执行task,经过1s再次执行

                                }
                            });

                        }
                    });
                }
            });
            isLoading = true;
            main_gallery.setVisibility(View.GONE);
            main_lin.setVisibility(View.GONE);
            //快照动画显示
            try {
                GifDrawable gifDrawable = new GifDrawable(getResources(), R.drawable.camera_picture_five);
                imgview.setImageDrawable(gifDrawable);
                imgview.setVisibility(View.VISIBLE);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    */
/**
     * 生成拍照后图片的中间矩形的宽度和高度
     *
     * @param w 屏幕上的矩形宽度，单位px
     * @param h 屏幕上的矩形高度，单位px
     * @return
     *//*

    private Point createCenterPictureRect(int w, int h) {

        int wScreen = DisplayUtil.getScreenMetrics(this).x;
        int hScreen = DisplayUtil.getScreenMetrics(this).y;
        int wSavePicture = doGetPrictureSize().y; //因为图片旋转了，所以此处宽高换位
        int hSavePicture = doGetPrictureSize().x; //因为图片旋转了，所以此处宽高换位
        float wRate = (float) (wSavePicture) / (float) (wScreen);
        float hRate = (float) (hSavePicture) / (float) (hScreen);
        float rate = (wRate <= hRate) ? wRate : hRate;//也可以按照最小比率计算

        int wRectPicture = (int) (w * wRate);
        int hRectPicture = (int) (h * hRate);
        return new Point(wRectPicture, hRectPicture);

    }

    public Point doGetPrictureSize() {
        Camera.Size s = mCamera.getParameters().getPictureSize();
        return new Point(s.width, s.height);
    }

    public Bitmap zoomImg(Bitmap bm, int newWidth, int newHeight) {
        // 获得图片的宽高   
        int width = bm.getWidth();
        int height = bm.getHeight();
        // 计算缩放比例   
        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;
        // 取得想要缩放的matrix参数   
        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHeight);
        // 得到新的图片   www.2cto.com
        Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
        return newbm;
    }

    boolean am = true;
    boolean pm = true;
    boolean night = true;
    boolean Fig;
    boolean DataFig;
    String Bigen;
    String End;
    Timer timer = new Timer(true);
    TimerTask task = new TimerTask() {

        @Override
        public void run() {
            handler.sendEmptyMessage(1);
        }
    };

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:

                    if (DatetimeUtil.TimeCompare(getSysDate("HH:mm"), "00:00", "11:59") && am) {
                        String sReStartFlag = mSharePreferenceUtil.getRestartFlag();
                        Log.d("HHH", "sReStartFlag" + sReStartFlag);
                        if (TextUtils.isEmpty(sReStartFlag)) {
                            mSharePreferenceUtil.setIndexBigen(0);
                            mSharePreferenceUtil.setIndexEnd(0);
                        } else {

                        }
                        am = false;
                        pm = true;
                        night = true;

                        String strAm = DatetimeUtil.getSysDate("yyyy-MM-dd") + "am";//am
                        if (sReStartFlag.equals(strAm)) {//说明当天am 已经加载过了,重启进入
                            isReStart = true;
                            Log.d("HHH", "说明当天am 已经加载过了,重启进入" + strAm);
                        } else {//第一次
                            Log.d("HHH", "说明当天am ,第一次进入" + strAm);
                            GetClass(strAm);
                            indexBigen = 0;
                            indexEnd = 0;
                            mSharePreferenceUtil.setIndexBigen(indexBigen);
                            mSharePreferenceUtil.setIndexEnd(indexEnd);
                        }

                    }
                    if (DatetimeUtil.TimeCompare(getSysDate("HH:mm"), "12:00", "17:59") && pm) {//
                        String sReStartFlag = mSharePreferenceUtil.getRestartFlag();
                        if (TextUtils.isEmpty(sReStartFlag)) {
                            mSharePreferenceUtil.setIndexBigen(0);
                            mSharePreferenceUtil.setIndexEnd(0);
                        }

                        am = true;
                        night = true;
                        pm = false;
                        Log.d("TAG", "下午");

                        String strPm = getSysDate("yyyy-MM-dd") + "pm";//pm

                        if (sReStartFlag.equals(strPm)) {//说明当天am 已经加载过了,重启进入
                            isReStart = true;
                            Log.d("HHH", "说明当天pm 已经加载过了,重启进入" + strPm);
                        } else {//第一次
                            GetClass(strPm);
                            Log.d("HHH", "说明当天pm ,第一次进入" + strPm);
                            indexBigen = 0;
                            indexEnd = 0;
                            mSharePreferenceUtil.setIndexBigen(indexBigen);
                            mSharePreferenceUtil.setIndexEnd(indexEnd);
                        }
                    }
                    if (DatetimeUtil.TimeCompare(getSysDate("HH:mm"), "18:00", "23:59") && night) {//
                        String sReStartFlag = mSharePreferenceUtil.getRestartFlag();
                        if (TextUtils.isEmpty(sReStartFlag)) {
                            mSharePreferenceUtil.setIndexBigen(0);
                            mSharePreferenceUtil.setIndexEnd(0);
                        }

                        am = true;
                        night = false;
                        pm = true;
                        Log.d("TAG", "晚上");

                        String strNight = getSysDate("yyyy-MM-dd") + "night";//night
                        if (sReStartFlag.equals(strNight)) {//说明当天am 已经加载过了,重启进入
                            isReStart = true;
                            Log.d("HHH", "strNight 已经加载过了,重启进入" + strNight);
                        } else {//第一次
                            GetClass(strNight);
                            Log.d("HHH", "strNight ,第一次进入" + strNight);
                            indexBigen = 0;
                            indexEnd = 0;
                            mSharePreferenceUtil.setIndexBigen(indexBigen);
                            mSharePreferenceUtil.setIndexEnd(indexEnd);
                        }

                    }


                    indexBigen = mSharePreferenceUtil.getIndexBigen();
                    indexEnd = mSharePreferenceUtil.getIndexEnd();
                    subscript = mSharePreferenceUtil.getSubscript();
                    Fig = mSharePreferenceUtil.getFig();
                    DataFig = mSharePreferenceUtil.getDataFig();

                    BigenCard = MyApp.getsInstance().getBigenCard();
                    EndCard = MyApp.getsInstance().getEndCard();
                    MeetingId = MyApp.getsInstance().getMeetingId();


                    //BIGEN2 获取缓存数据
                    if (isReStart) {
                        isReStart = false;
                        list.clear();
                        MeetingId.clear();
                        BigenCard.clear();
                        EndCard.clear();
                        List<String> MeetingIdT = (List<String>) MyFileUtils.readFile2Object1(MyFileUtils.MeetingId, new TypeToken<List<String>>() {
                        }.getType());
                        MeetingId.addAll(MeetingIdT);

                        List<String> BigenCardT = (List<String>) MyFileUtils.readFile2Object1(MyFileUtils.BigenCard, new TypeToken<List<String>>() {
                        }.getType());
                        BigenCard.addAll(BigenCardT);

                        List<String> EndCardT = (List<String>) MyFileUtils.readFile2Object1(MyFileUtils.EndCard, new TypeToken<List<String>>() {
                        }.getType());
                        EndCard.addAll(EndCardT);
                        MyApp.getsInstance().setMeetingId(MeetingId);
                        MyApp.getsInstance().setBigenCard(BigenCard);
                        MyApp.getsInstance().setEndCard(EndCard);

                        List<PersonnelResutl> mlist = (List<PersonnelResutl>) MyFileUtils.readFile2Object1(MyFileUtils.mListBean, new TypeToken<List<PersonnelResutl>>() {
                        }.getType());

                        if (mlist != null && mlist.size() > 0) {
                            Log.e(TAG, "重启---Bigen-" + Bigen + "mlist.get(0).getmCurrenTime()--" + mlist.get(0).getmCurrenTime());

                            list.addAll(mlist);

                            sortClass sort = new sortClass();
                            Collections.sort(list, sort);

                            attendanceAdapter = new AttendanceAdapter(MeMainActivity.this);
                            listView.setAdapter(attendanceAdapter);
                            attendanceAdapter.clear();
                            attendanceAdapter.setDate(list);
                            practical.setText(mSharePreferenceUtil.getRealized() + "/" + list.size() + "");


                        }

                        List<String> mli = (List<String>) MyFileUtils.readFile2Object1(MyFileUtils.mListAttachUrl, new TypeToken<List<String>>() {
                        }.getType());
                        if (mli != null && mli.size() > 0) {
                            Log.e("TAG", "重启-mli-ArrURl-" + mli.get(0) + "");
                            if (li != null && li.size() > 0) {
                                li.clear();
                            }
                            li.addAll(mli);
                            gallery_adapter.setList(li);
                            setCircle();
                        }

                    }


                    if (true) {
                        Log.d("TAG", "Enter  BigenCard size---" + BigenCard.size());
                        Log.d("TAG", "Enter  BigenCard size---" + EndCard.size());
                        Log.d("TAG", "res=" + (BigenCard.size() != 0 && indexBigen < BigenCard.size() && indexEnd < EndCard.size()) + "");
                    }
                    if (BigenCard.size() != 0 && indexBigen < BigenCard.size() && indexEnd < EndCard.size()) {//
                        if (indexBigen >= BigenCard.size() || indexEnd >= EndCard.size()) {
                            indexBigen = BigenCard.size() - 1;
                            indexEnd = EndCard.size() - 1;
                        }
                        MeetingResutl meetingResutl;
                        RealmResults<MeetingResutl> dog = realmHelper.querMeetingResutllById(MeetingId.get(indexBigen));
                        if (null != dog && dog.size() > 0) {
                            meetingResutl = realmHelper.querMeetingResutll(MeetingId.get(indexBigen));
                        } else {
                            Log.d("TAG", "dog==null");
                            return;
                        }

                        Bigen = DatetimeUtil.getDateTimeFromMillisecond(
                                DatetimeUtil.TimeStrToSecond(BigenCard.get(indexBigen)) - 1000 * 60 * (meetingResutl.getInBefore()));

                        if (meetingResutl.getNeedCheckout() == 1) {
                            End = DatetimeUtil.getDateTimeFromMillisecond(
                                    DatetimeUtil.TimeStrToSecond(EndCard.get(indexEnd)) + 1000 * 60 * (meetingResutl.getOutLate()));

                        } else {
                            End = DatetimeUtil.getDateTimeFromMillisecond(
                                    DatetimeUtil.TimeStrToSecond(EndCard.get(indexEnd)));

                        }

//                        Bigen = DatetimeUtil.getDateTimeFromMillisecond(
//                                DatetimeUtil.TimeStrToSecond(BigenCard.get(indexBigen))  );
//                        End = DatetimeUtil.getDateTimeFromMillisecond(
//                                DatetimeUtil.TimeStrToSecond(EndCard.get(indexEnd)) );


                        Log.e("TAG", "开始时间：" + Bigen + "kk" + BigenCard.get(indexEnd));
                        Log.e("TAG", "结束时间：" + End + "kk" + EndCard.get(indexEnd));
                        Log.e("TAG", "getInBefore：" + meetingResutl.getInBefore());
                        Log.e("TAG", "getOutLate：" + meetingResutl.getOutLate());
                        //重启机制
                        Log.d("TAG", "kk1" + DatetimeUtil.TimeCompare(getSysDate("HH:mm"), DatetimeUtil.gethour(Bigen), DatetimeUtil.gethour(End)));
                        Log.d("TAG", "kk2" + !subscript);
                        //
                        if (DatetimeUtil.TimeCompare(getSysDate("HH:mm"), DatetimeUtil.gethour(Bigen), DatetimeUtil.gethour(End)) && (!subscript)) {
                            mSharePreferenceUtil.setSubscript(true);
                            mSharePreferenceUtil.setIndexBigen(indexBigen);
                            Log.d("TAG", "在范围：");
                            li.clear();


                            for (int i = 0; i < realmHelper.QueryImag(MeetingId.get(mSharePreferenceUtil.getIndexBigen())).size(); i++) {
                                Attachment attachment = ((Attachment) realmHelper.QueryImag(MeetingId.get(mSharePreferenceUtil.getIndexBigen())).get(i));
                                li.add(attachment.getAttachUrl());
                            }
//                    Log.d("TAG","url:"+attachment.getAttachUrl());
                            Log.d("TAG", "li:" + li.size());
                            if (li.size() != 0) {
                                gallery_adapter.setList(li);
                                setCircle();
                            }

                            list = realmHelper.queryDobByAge(MeetingId.get(mSharePreferenceUtil.getIndexBigen()));
                            practical.setText(mSharePreferenceUtil.getRealized() + "/" + list.size());
                            Log.d("TAG", "list:" + list.size());
                            listView.setVisibility(View.VISIBLE);
                            attendanceAdapter = new AttendanceAdapter(MeMainActivity.this);
                            listView.setAdapter(attendanceAdapter);
//                            attendanceAdapter.clear();
                            attendanceAdapter.setDate(list);
                            PersonnelResutl resutl = realmHelper.FandPersonnelResultByMedtingId(MeetingId.get(mSharePreferenceUtil.getIndexBigen()), 0);
                            if (null != resutl) {
                                realmHelper.UpdateFindllTye(MeetingId.get(mSharePreferenceUtil.getIndexBigen()), 0);
                            }

                            mSharePreferenceUtil.setFig(false);

                            ThreadUtil.getInstance().submit(new Runnable() {
                                @Override
                                public void run() {
                                    MyFileUtils.deleteFile(MyFileUtils.mListBean);
                                    list.get(0).setmCurrenTime(Bigen);
                                    boolean isSave = MyFileUtils.saveObject2File(list, MyFileUtils.mListBean);
                                    Log.d(TAG, "默认保存 缓存数据-PersonnelResutl-" + isSave);

                                    boolean isSaveUrl = MyFileUtils.saveObject2File(li, MyFileUtils.mListAttachUrl);
                                    Log.d(TAG, "默认保存课程图片URL保存--" + isSaveUrl);
                                }
                            });
                        }
                        Log.d("TAG", "fig:" + Fig);
                        if (getSysDate("yyyy-MM-dd HH:mm:ss").equals(End) && (!Fig)) {
                            Log.d(TAG, "按节次开始准备上传-");
                            UploadCheck(DataFig);
                            mSharePreferenceUtil.setSubscript(false);
                            practical.setText(0 + "/" + 0);
                            realized = 0;
                            mSharePreferenceUtil.setRealized(0);
                            indexEnd++;
                            indexBigen++;
                            mSharePreferenceUtil.setIndexEnd(indexEnd);
                            mSharePreferenceUtil.setIndexBigen(indexBigen);
                            listView.setVisibility(View.GONE);
                            attendanceAdapter.clear();
                            Log.d("TAG", "清除不同时区的所有缓存 数据...");
                            ThreadUtil.getInstance().submit(new Runnable() {
                                @Override
                                public void run() {
                                    MyFileUtils.deleteFile(MyFileUtils.mListBean);//
                                    MyFileUtils.deleteFile(MyFileUtils.mListAttachUrl);//
                                    mSharePreferenceUtil.setRestartFlag("");
                                    mSharePreferenceUtil.setIndexEnd(0);
                                    mSharePreferenceUtil.setIndexBigen(0);
                                }
                            });

                        }

                        Log.d("TAG", "时间：" + DatetimeUtil.gethour(DatetimeUtil.getDateTimeFromMillisecond(
                                DatetimeUtil.TimeStrToSecond(End) + 1000 * 60 * 3)));

//                        if (DatetimeUtil.TimeCompare(DatetimeUtil.getSysDate("HH:mm"), DatetimeUtil.gethour(End), DatetimeUtil.gethour(DatetimeUtil.getDateTimeFromMillisecond(
//                                DatetimeUtil.TimeStrToSecond(End) + 1000 * 60 * 3))) && (!Fig)) {
//                            UploadCheck(DataFig);
//                            mSharePreferenceUtil.setSubscript(false);
//                            practical.setText(0 + "/" + 0);
//                            mSharePreferenceUtil.setRealized(0);
////                        mSharePreferenceUtil.setIndexEnd(indexEnd);
//                            Log.d("TAG", "3分钟上传");
//                        }

                    }


                    break;

                case 2:
                    Log.d("TAG", " 接受 Message message===2");
                    isLoading = false;
                    Date curDate = new Date(System.currentTimeMillis());
                    long time = curDate.getTime() - startTime;
                    Log.d("www1", "接受 延迟后 400 完成整个拍照显示图片时间：" + time);
                    imgview.setImageBitmap(null);
                    main_gallery.setVisibility(View.VISIBLE);
                    main_lin.setVisibility(View.VISIBLE);
                    imgview.setVisibility(View.GONE);

                    if (MyDialog != null) {
                        MyDialog.dismiss();
                    }

                    if (timerImgView != null) {
                        taskImgView.cancel();
                    }
                    if (timer != null) {
                        task.cancel();
                    }
                    timer = new Timer();
                    task = new TimerTask() {
                        @Override
                        public void run() {
                            // 需要做的事:发送消息  
                            Message message = new Message();
                            message.what = 1;
                            handler.sendMessage(message);
                        }
                    };
                    timer.schedule(task, 1000, 1000);// 1s后执行task,经过1s再次执行

                    break;
                case 3:
                    SetData(tiem);
                    break;
                case 4:

                    break;

            }
        }
    };

    private void Date(String name) {
        realized = mSharePreferenceUtil.getRealized();
        MeetingCheck meetingCheck = new MeetingCheck();
        indexBigen = mSharePreferenceUtil.getIndexBigen();


//        list = realmHelper.queryDobByAge(MeetingId.get(mSharePreferenceUtil.getIndexBigen()));
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getWlkh() != null) {
                if (list.get(i).getWlkh().equals(name)) {
                    Log.d("www", list.get(i).toString());
                    list.get(i).setTime(getSysDate("HH:mm:ss"));
                    realmHelper.UpdateDog(name, MeetingId.get(mSharePreferenceUtil.getIndexBigen()), getSysDate("HH:mm:ss"));
//                    meetingCheck.setClassId(list.get(i).getClassId());
                    meetingCheck.setInResult("4");
                    meetingCheck.setTermCode(mSharePreferenceUtil.getClassId());
                    meetingCheck.setLg("0");
                    meetingCheck.setMeetingId(list.get(i).getMeetingId());
                    meetingCheck.setUserId(list.get(i).getUserId());
                    meetingCheck.setTime(getSysDate("yyyy-MM-dd HH:mm:ss"));
                    Log.d("TAG", "Time:" + meetingCheck.getTime());
                    Log.d("TAG", "getInResult:" + meetingCheck.getInResult());
                    if (meetingCheck.getInResult().equals("1")) {
                        meetingCheck.setAttendResult("1");
                    } else if (meetingCheck.getInResult().equals("2")) {
                        meetingCheck.setAttendResult("2");

                    } else if (meetingCheck.getInResult().equals("4")) {
                        meetingCheck.setAttendResult("4");
                    }
                    meetingCheck.setWlkh(name);
                    if (list.get(i).getType() == 0) {
                        realized++;
                        mSharePreferenceUtil.setRealized(realized);
                    }
                    list.get(i).setType(1);
                    Log.d("TAG", "type:" + list.get(i).getType());
                    realmHelper.UpdateDogTye(name, MeetingId.get(mSharePreferenceUtil.getIndexBigen()), 1);
                    meetingCheck.setOutResult("0");
                    realmHelper.addDog(meetingCheck);

                }
            }
        }

      */
/*  practical.setText(mSharePreferenceUtil.getRealized() + "/" + list.size() + "");
        attendanceAdapter.notifyDataSetChanged();*//*



        sortClass sort = new sortClass();
        Collections.sort(list, sort);
        //  list = realmHelper.queryDobByAge(MeetingId.get(mSharePreferenceUtil.getIndexBigen()));
        practical.setText(mSharePreferenceUtil.getRealized() + "/" + list.size());
        attendanceAdapter.clear();
        attendanceAdapter.setDate(list);
        attendanceAdapter.notifyDataSetChanged();
        ThreadUtil.getInstance().submit(new Runnable() {
            @Override
            public void run() {
                MyFileUtils.deleteFile(MyFileUtils.mListBean);
                list.get(0).setmCurrenTime(Bigen);
                boolean isSave = MyFileUtils.saveObject2File(list, MyFileUtils.mListBean);
                Log.d("TAG", "刷卡保存--" + isSave);
            }
        });
    }

    private void UploadCheck(boolean dataFig) {
        Log.d("TAG", "fig1:" + Fig);
        BigenCard = MyApp.getsInstance().getBigenCard();
        indexEnd = mSharePreferenceUtil.getIndexEnd();
        MeetingId = MyApp.getsInstance().getMeetingId();

        MeetingResutl meetingResutl;
        RealmResults<MeetingResutl> dog = realmHelper.querMeetingResutllById(MeetingId.get(indexBigen));
        if (null != dog && dog.size() > 0) {
            meetingResutl = realmHelper.querMeetingResutll(MeetingId.get(indexBigen));
        } else {
            Log.e("TAG", "UploadCheck -dog==null");
            return;
        }

        list = realmHelper.queryDobByAge(MeetingId.get(indexEnd));
        Log.d("TAG", "list:" + list.size());
        if (list.size() != 0 && (!dataFig)) {
            for (int i = 0; i < list.size(); i++) {
                Log.d("TAG", "list:" + list.get(i).getWlkh());
                if (realmHelper.QueryTraineeId(list.get(i).getUserId(), list.get(i).getMeetingId()).size() == 0) {
                    MeetingCheck meetingCheck = new MeetingCheck();
                    meetingCheck.setInResult("4");
                    meetingCheck.setMeetingId(list.get(i).getMeetingId());
                    meetingCheck.setTermCode(mSharePreferenceUtil.getClassId());
                    meetingCheck.setLg("-1");
                    meetingCheck.setTime(null);
                    meetingCheck.setWlkh(list.get(i).getWlkh());
                    meetingCheck.setOutResult("0");
                    meetingCheck.setAttendResult("4");
                    meetingCheck.setUserId(list.get(i).getUserId());
                    Log.d("TAG", "UserId:" + list.get(i).getUserId());
                    realmHelper.addDog(meetingCheck);
                }

                if (meetingResutl.getNeedCheckout() == 1) {
                    Log.d("TAG", "UserId:" + list.get(i).getUserId());
                    Log.d("TAG", "QueryTraineeId:" + realmHelper.QueryTraineeId(list.get(i).getUserId(), list.get(i).getMeetingId()).size());


                    if (realmHelper.QueryTraineeId(list.get(i).getUserId(), list.get(i).getMeetingId()).size() == 1) {
                        if (DatetimeUtil.Getminutes(realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getTime(), BigenCard.get(indexBigen)) <= (meetingResutl.getBeLate() + meetingResutl.getAbsenteeism())) {
                            realmHelper.updateInResultOne(list.get(i).getWlkh(), "1");
                        } else {
                            realmHelper.updateInResultOne(list.get(i).getWlkh(), "2");

                        }
                        if (DatetimeUtil.Getminutes(realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getTime(), EndCard.get(indexEnd)) <= (meetingResutl.getOutBefore() + meetingResutl.getOutLate())) {
                            realmHelper.updateOutResultOne(list.get(i).getWlkh(), "1");

                        }
                        if (DatetimeUtil.Getminutes(EndCard.get(indexEnd), realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getTime()) <= (meetingResutl.getOutBefore() + meetingResutl.getLeaveEarly())) {
                            realmHelper.updateOutResultOne(list.get(i).getWlkh(), "1");

                        } else {
                            realmHelper.updateOutResult(list.get(i).getWlkh(), "3");

                        }

                        if (realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult().equals("1") && realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getOutResult().equals("1")) {
                            realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), "1");

                        } else if (realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult().equals("2") && realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getOutResult().equals("1")) {
                            realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), "2");

                        } else if (realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult().equals("1") && realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getOutResult().equals("3")) {
                            realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), "3");

                        } else if (realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult().equals("2") && realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getOutResult().equals("3")) {
                            realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), "5");

                        } else {
                            realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult());
                            realmHelper.updateAttendResult(list.get(i).getWlkh(), realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult());
                        }
                        realmHelper.UpdateLgOne(list.get(i).getWlkh(), "0");  //改状态
                        if (DatetimeUtil.Getminutes(realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getTime(), BigenCard.get(indexBigen)) <= (meetingResutl.getBeLate() + meetingResutl.getAbsenteeism())) {
                            realmHelper.updateInResultOne(list.get(i).getWlkh(), "1");

                        } else {
                            realmHelper.updateInResultOne(list.get(i).getWlkh(), "2");
                        }
                        if (realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getTime() == null) {
                            realmHelper.UpdateLgOne(list.get(i).getWlkh(), "-1");
                            realmHelper.updateInResultOne(list.get(i).getWlkh(), "4");
                            realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), "4");


                        }
//

                        Log.d("TAG", "1");
                    } else if (realmHelper.QueryTraineeId(list.get(i).getUserId(), list.get(i).getMeetingId()).size() >= 2) {
                        Log.d("TAG", "2");
                        realmHelper.UpdateLgLate(list.get(i).getWlkh());
                        realmHelper.UpdateLgOne(list.get(i).getWlkh(), "0");
                        if (DatetimeUtil.Getminutes(realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getTime(), BigenCard.get(indexBigen)) <= (meetingResutl.getBeLate() + meetingResutl.getAbsenteeism())) {
                            realmHelper.updateInResultOne(list.get(i).getWlkh(), "1");
                            realmHelper.updateInResult(list.get(i).getWlkh(), "1");
                        } else {
                            realmHelper.updateInResultOne(list.get(i).getWlkh(), "2");
                            realmHelper.updateInResult(list.get(i).getWlkh(), "2");
                        }
                        if (DatetimeUtil.Getminutes(realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getTime(), EndCard.get(indexEnd)) <= (meetingResutl.getOutBefore() + meetingResutl.getOutLate())) {
                            realmHelper.updateOutResultOne(list.get(i).getWlkh(), "1");
                            realmHelper.updateOutResult(list.get(i).getWlkh(), "1");
                        }
                        if (DatetimeUtil.Getminutes(EndCard.get(indexEnd), realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getTime()) <= (meetingResutl.getOutBefore() + meetingResutl.getLeaveEarly())) {
                            realmHelper.updateOutResultOne(list.get(i).getWlkh(), "1");
                            realmHelper.updateOutResult(list.get(i).getWlkh(), "1");
                        } else {
                            realmHelper.updateOutResult(list.get(i).getWlkh(), "3");
                            realmHelper.updateOutResultOne(list.get(i).getWlkh(), "3");
                        }
                        Log.d("TAG", "第一条时间：" + realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getTime());
                        Log.d("TAG", "最后一条时间：：" + realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getTime());
                        if (realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult().equals("1") && realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getOutResult().equals("1")) {
                            realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), "1");
                            realmHelper.updateAttendResult(list.get(i).getWlkh(), "1");
                        } else if (realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult().equals("2") && realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getOutResult().equals("1")) {
                            realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), "2");
                            realmHelper.updateAttendResult(list.get(i).getWlkh(), "2");
                        } else if (realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult().equals("1") && realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getOutResult().equals("3")) {
                            realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), "3");
                            realmHelper.updateAttendResult(list.get(i).getWlkh(), "3");
                        } else if (realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult().equals("2") && realmHelper.queryDogByIdLast(list.get(i).getWlkh()).getOutResult().equals("3")) {
                            realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), "5");
                            realmHelper.updateAttendResult(list.get(i).getWlkh(), "5");
                        } else {
                            realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult());
                            realmHelper.updateAttendResult(list.get(i).getWlkh(), realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getInResult());
                        }

                    }
                    if (realmHelper.QueryTraineeId(list.get(i).getUserId(), list.get(i).getMeetingId()).size() >= 2) {
                        list1.add(realmHelper.QueryTraineeIdOne(list.get(i).getUserId(), list.get(i).getMeetingId(), 1));
                        list1.add(realmHelper.QueryTraineeIdOne(list.get(i).getUserId(), list.get(i).getMeetingId(), 2));
                    } else if (realmHelper.QueryTraineeId(list.get(i).getUserId(), list.get(i).getMeetingId()).size() == 1 || realmHelper.QueryTraineeId(list.get(i).getUserId(), list.get(i).getMeetingId()).size() == 0) {
                        list1.add(realmHelper.QueryTraineeIdOne(list.get(i).getUserId(), list.get(i).getMeetingId(), 1));
                    }
                    Log.d("TAG", "开启签退");
                } else {
                    if (realmHelper.QueryTraineeId(list.get(i).getUserId(), list.get(i).getMeetingId()).size() >= 1) {
                        if (DatetimeUtil.Getminutes(realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getTime(), BigenCard.get(indexBigen)) <= (meetingResutl.getBeLate() + meetingResutl.getAbsenteeism())) {
                            realmHelper.updateInResultOne(list.get(i).getWlkh(), "1");
                            realmHelper.updateAttendResult(list.get(i).getWlkh(), "1");
                        } else {
                            realmHelper.updateInResultOne(list.get(i).getWlkh(), "2");
                            realmHelper.updateAttendResult(list.get(i).getWlkh(), "2");

                        }
                    }
//                    realmHelper.updateOutResultOne(list.get(i).getWlkh(), "1");
                    realmHelper.UpdateLgOne(list.get(i).getWlkh(), "0");  //改状态
                    if (realmHelper.queryDogByIdOne(list.get(i).getWlkh()).getTime() == null) {
                        realmHelper.UpdateLgOne(list.get(i).getWlkh(), "-1");
                        realmHelper.updateInResultOne(list.get(i).getWlkh(), "4");
                        realmHelper.updateAttendResultOne(list.get(i).getWlkh(), list.get(i).getUserId(), "4");
                    }
                    list1.add(realmHelper.QueryTraineeIdOne(list.get(i).getUserId(), list.get(i).getMeetingId(), 1));
                    Log.d("TAG", "没开启签退");
                }

            }


        }


        mSharePreferenceUtil.setDataFig(true);
        String json = JSON.toJSONString(list1);
        Log.d("TAG", "json:" + json);
        Log.d("TAG", "list1:" + list1.size());

        Subscriber subscr = new AbsAPICallback<Resutl>(this) {
            @Override
            public void onCompleted() {
                Log.d("TAG", "上传失败");
            }


            @Override
            public void onNext(Resutl resul) {
                Log.d("TAG", "resul:" + resul.getMessage());
                Log.d("TAG", "isCode:" + resul.isCode());
                Log.d("TAG", "上传成功");
                if (resul.isCode()) {
                    MyFileUtils.deleteFile(MyFileUtils.mListBean);
                    MyFileUtils.deleteFile(MyFileUtils.mListAttachUrl);
                    mSharePreferenceUtil.setRestartFlag("");
                    mSharePreferenceUtil.setIndexEnd(0);
                    mSharePreferenceUtil.setIndexBigen(0);

                    realmHelper.deleteDogMeeting(list.get(indexBigen).getMeetingId());
                    realmHelper.deleteDog(list.get(indexBigen).getMeetingId());
                    list1.clear();
                    mSharePreferenceUtil.setRealized(0);
                    mSharePreferenceUtil.setFig(true);
                    mSharePreferenceUtil.setDataFig(false);
                    list.clear();
                    attendanceAdapter.notifyDataSetChanged();

                }

            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                Log.i("TAG", "e：" + e.getMessage());
                Log.d("TAG", "上传失败");
            }
        };
        Api.getInstance().UploadCheck(subscr, json);


    }

    private <VT extends View> VT getView(@IdRes int id) {
        return (VT) findViewById(id);
    }


    private class SufaceListener implements SurfaceHolder.Callback {
        private boolean isPreview;

        @Override
        public void surfaceCreated(SurfaceHolder surfaceHolder) {
            try {
                WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
                Display display = wm.getDefaultDisplay();
                //int num = mCamera.getNumberOfCameras();
                mCamera = Camera.open(0);
                Camera.Parameters parameters = mCamera.getParameters();
                List<Camera.Size> vSizeList = parameters.getSupportedPictureSizes();

                for (int num = 0; num < vSizeList.size(); num++) {
                    Camera.Size vSize = vSizeList.get(num);
                }

                if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
                    //如果是竖屏
                    mCamera.setDisplayOrientation(90);
                } else {
                    mCamera.setDisplayOrientation(180);
                }
                parameters.setPictureFormat(PixelFormat.JPEG);
                mCamera.setParameters(parameters);
                mCamera.setPreviewDisplay(mSurfaceHolder);
                mCamera.startPreview();
                isPreview = true;
                Log.d("TAG", "执行");
            } catch (Exception e) {
                Toast.makeText(MeMainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                Log.d("TAG", "e:" + e.getMessage());
            }
        }

        @Override
        public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
            if (mSurfaceHolder == null) {
                // preview surface does not exist
                return;
            }

            // stop preview before making changes
            try {
                if (mCamera != null) {
                    mCamera.stopPreview();

                }

            } catch (Exception e) {
                // ignore: tried to stop a non-existent preview
            }

            try {
                mCamera.setPreviewDisplay(mSurfaceHolder);
                mCamera.startPreview();

            } catch (Exception e) {

            }
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
            if (mCamera != null) {
                if (isPreview) mCamera.stopPreview();
                mCamera.release();
                mCamera = null;
            }
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        //销毁activity之前先关闭定时器
        if (handler != null) {
            if (timeadv != null) {
                handler.removeCallbacks(timeadv);
            }
        }
        RxBus.get().unregister(this);
        if (MyDialog != null) {
            MyDialog.dismiss();
            MyDialog = null;
        }

    }

    private void loadMusic() {
        soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 5);
        soundPool1 = new SoundPool(10, AudioManager.STREAM_MUSIC, 5);
        soundPool2 = new SoundPool(10, AudioManager.STREAM_MUSIC, 5);
        failure = soundPool1.load(this, R.raw.failure, 0);
        sourceid = soundPool.load(this, R.raw.media, 0);
        credit = soundPool2.load(this, R.raw.q_ni_already_dao, 0);
        soundPool
                .setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {

                    public void onLoadComplete(SoundPool soundPool,
                                               int sampleId, int status) {
                        isSoundReady = true;

                    }
                });
        soundPool1
                .setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {

                    public void onLoadComplete(SoundPool soundPool,
                                               int sampleId, int status) {
                        isSoundReady = true;

                    }
                });
        soundPool2
                .setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {

                    public void onLoadComplete(SoundPool soundPool,
                                               int sampleId, int status) {
                        isSoundReady = true;

                    }
                });


    }


    private void SetData(TextView tiem) {
        tiem.setText(getSysDate("HH:mm:ss"));
    }

    public class MyThread implements Runnable {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            while (true) {
                try {
                    Thread.sleep(1000);//线程暂停1秒，单位毫秒
                    Message message = new Message();
                    message.what = 3;
                    handler.sendMessage(message);//发送消息
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.set:
                SetDiagFragment setDiagFragment = new SetDiagFragment();
                setDiagFragment.show(getFragmentManager(), SetDiagFragment.class.getName());

                break;
        }
    }

    ;


    private class DispQueueThread extends Thread {
        private Queue<ComBean> QueueList = new LinkedList<ComBean>();

        @Override
        public void run() {
            super.run();
            while (!isInterrupted()) {
                final ComBean ComData;
                while ((ComData = QueueList.poll()) != null) {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            DispRecDataTest(ComData);
                        }
                    });
                    try {
                        Thread.sleep(100);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                }
            }
        }

        public synchronized void AddQueue(ComBean ComData) {
            QueueList.add(ComData);
        }
    }

    String cardId = "";// 当前 刷卡卡号临时变量
    private CountDownTimer mDownTimer;

    private void startDowntime() {
        if (null == mDownTimer) {
            initDownTime();
        } else {
            mDownTimer.start();
        }
    }

    private final int TIME = 1000 * 1;//每1秒更新界面 年月日 时分秒

    private void initDownTime() {
        mDownTimer = new CountDownTimer(TIME, 1000) {
            @Override
            public void onTick(long l) {

                Log.d("dowm==", "onTick--");
            }

            @Override
            public void onFinish() {
                Log.d("dowm==", "onFinish");
                if (null != myActivity) {
                    cardId = "";
                    Log.d("dowm==", "onFinish 1秒后 TIME isOne--cardId = 空");
                    mDownTimer.cancel();
                }

            }


        };
        mDownTimer.start();
    }

    private void DispRecDataTest(ComBean ComRecData) {

      */
/*  StringBuilder sMsg = new StringBuilder();
        sMsg.append(ComRecData.sRecTime);
        sMsg.append("[");
        sMsg.append(ComRecData.sComPort);
        sMsg.append("]");
        sMsg.append("[Hex] ");*//*

//        if (!isValid()) {
//            setRecvData(ComRecData.bRec);
//            //解析 TLV 格式数据
//
//            setValidDataFlag(true);
//        }


        Log.d("res", MyFunc.ByteArrToHex(ComRecData.bRec));
        // 10/17直接获取ID
        String resData = MyFunc.ByteArrToHex(ComRecData.bRec).trim();
        Log.d("res", "resData.length=" + resData.length());
        if (resData.endsWith("6B BB") && resData.length() >= 38) {
            Log.d("res", "10/17直接获取ID");
            String re = resData.substring(resData.length() - 20, resData.length() - 9);
            System.out.println(re);
            String[] rr = re.split(" ");
            String[] dd = new String[4];
            StringBuilder sb = new StringBuilder();
            dd[0] = rr[3];
            dd[1] = rr[2];
            dd[2] = rr[1];
            dd[3] = rr[0];
            for (int i = 0; i < dd.length; i++) {
                System.out.println(dd[i]);
                sb.append(dd[i]);
            }
            String factoryFixID = sb.toString();
            Log.d("res", "物理卡号：factoryFixID=" + factoryFixID + "cardId=" + cardId);
            if (!TextUtils.isEmpty(factoryFixID)) {
                Log.d("res", "刷卡成功");
                if (cardId.equals(factoryFixID)) {
                    Log.d("res", "连刷----");
                    startDowntime();
                    return;
                } else {
                    cardId = factoryFixID;
                    Log.d("res", "第一次刷----cardId -16=" + cardId + "cardId-10=");

                    if (!isLoading) {
                        */
/*if(cardId.equals("733D48E4")){
                            Object object=null;
                            object.toString();
                        }*//*

                        doExecCard(cardId);
                    } else {
                        Log.d("res", "正在上传中----");
                    }
                }
            }














         */
/*   String strFix="2941840887";

            if(!TextUtils.isEmpty(strFix)){
                strFix=Long.toHexString(Long.valueOf(strFix));
            }
            if(strFix.equalsIgnoreCase(sb.toString())){
                Log.d("res","刷卡成功");
            }else{
                Log.d("res","刷卡失败");
            }*//*



        } else {
            Log.d("res", "获取数据异常--");
        }


        //

        //测试
      */
/*  List<TLV> mlist= MyFunc.ByteArrToHexBB(ComRecData.bRec);

        String strFix="2941840887";

        if(!TextUtils.isEmpty(strFix)){
            strFix=Long.toHexString(Long.valueOf(strFix));
        }

        if(mlist!=null && mlist.size()>1){
            Log.d("res", mlist.get(1).value);
            if(strFix.equalsIgnoreCase(mlist.get(1).value)){
                Log.d("res","刷卡成功");
            }else{
                Log.d("res","刷卡失败");
            }
        }
        //
        sMsg.append(MyFunc.ByteArrToHex(ComRecData.bRec));


        sMsg.append("\r\n");
*//*


    }

    private void doExecCard(String mCardId) {
        Log.d(TAG, "cardInfo:" + mCardId);
        Long strl = Long.parseLong(mCardId, 16);
        String cardId = strl.toString();
        Log.d(TAG, "cardInfo:fixId" + cardId);
        //测试
       */
/* if (true) {
            takePicture("1001");
            return;
        }*//*

        //

        //Bug
        if (MeetingId == null || MeetingId.size() <= 0) {
            Log.d("TAG", "cardInfo:MeetingId.size()=" + MeetingId.size());
            soundPool1.play(1, 1, 1, 0, 0, 1);
            return;
        }
        //
        MeetingResutl meetingResutl;
        RealmResults<MeetingResutl> dog = realmHelper.querMeetingResutllById(MeetingId.get(indexBigen));
        if (null != dog && dog.size() > 0) {
            meetingResutl = realmHelper.querMeetingResutll(MeetingId.get(indexBigen));
        } else {
            Log.e("TAG", "dog==null");
            return;
        }
        //MeetingResutl meetingResutl = realmHelper.querMeetingResutll(MeetingId.get(indexBigen));
        Log.d("www", "cardInfo:" + cardId);
        BigenCard = MyApp.getsInstance().getBigenCard();
        if (BigenCard.size() != 0 && indexBigen < BigenCard.size() && indexEnd < EndCard.size()) {
            String Bigen = DatetimeUtil.getDateTimeFromMillisecond(DatetimeUtil.TimeStrToSecond(BigenCard.get(indexBigen)) - 1000 * 60 * (meetingResutl.getInBefore()));
//            String End = DatetimeUtil.getDateTimeFromMillisecond(
//                    DatetimeUtil.TimeStrToSecond(EndCard.get(indexEnd)) + 1000 * 60 * (meetingResutl.getLeaveEarly()));

            if (meetingResutl.getNeedCheckout() == 1) {
                End = DatetimeUtil.getDateTimeFromMillisecond(
                        DatetimeUtil.TimeStrToSecond(EndCard.get(indexEnd)) + 1000 * 60 * (meetingResutl.getOutLate()));

            } else {
                End = DatetimeUtil.getDateTimeFromMillisecond(
                        DatetimeUtil.TimeStrToSecond(EndCard.get(indexEnd)));

            }


            if (realmHelper.isDogExist(cardId, MeetingId.get(indexBigen))) {
                if (DatetimeUtil.TimeCompare(getSysDate("HH:mm"), DatetimeUtil.gethour(Bigen), DatetimeUtil.gethour(End))) {
                    int count = realmHelper.queryDogListMeeting(cardId, MeetingId.get(indexBigen)).size();
                    Log.d("www", "count" + count + " cardId" + cardId);
                    if (realmHelper.queryDogListMeeting(cardId, MeetingId.get(indexBigen)).size() == 1 && (meetingResutl.getNeedCheckout()) == 0) {
                        Log.d("www", "已签到过");
                        //你已签到过
                        soundPool2.play(1, 1, 1, 0, 0, 1);
                    } else {
                        Log.d("www", "第一次签到");
                        if (isSoundReady) {
                            Date(cardId);
                            takePicture(cardId);
                            soundPool.play(1, 1, 1, 0, 0, 1);


                        }
                    }

                } else {
                    Toast.makeText(MeMainActivity.this, "您暂时没有需要签到的会议", Toast.LENGTH_SHORT).show();
                    soundPool1.play(1, 1, 1, 0, 0, 1);
                }
            } else {
                Log.d("TAG", "空");
                soundPool1.play(1, 1, 1, 0, 0, 1);
                Toast.makeText(MeMainActivity.this, "您不在该此会议开会", Toast.LENGTH_SHORT).show();
            }
        } else {
            soundPool1.play(1, 1, 1, 0, 0, 1);
        }


    }
}
*/
